<?php
namespace Seller\Model;
use Think\Model;
// 页面模块
class TempItemModel extends Model
{
    // 拿一个随机节点
    static public function get_rand_node()
    {
        return substr(md5(rand(1000 ,9999). time()),-5);
    }
    // 跳转链接
    public function get_link( $link_key )
    {
        $link_arr = array(
            "javascript:;", U("Home/Setting/personal") ,U("Home/Index/index")
        );
        return $link_arr[$link_key];
    }
    // $node_num    节点数量
    // $page_style  页面样式
    public function goods( $goods_param )
    {
        $node_num = self::get_rand_node();
        if(!empty($goods_param)){
            if($goods_param['goods_ids'] != ''){
                $where = "id IN ({$goods_param['goods_ids']})";
                $m_goods = M("good")->where($where)->field("id,img,g_name,price")->order("sale_num desc")->select();
                $cats = array();
            }
            elseif ($goods_param['cats_ids'] != ''){
                $where = "shelves = 1 AND cate IN ({$goods_param['cats_ids']}) AND shop_id = ".session("shop_id");
                $limit = $goods_param['style'] == 1 ? "0,9" :"0,6";
                $m_goods = M("good")->where($where)->field("id,img,g_name,price")->order("sale_num desc")->limit($limit)->select();
                $cats = M("category")->where("id IN ({$goods_param['cats_ids']})")->field("id,c_name")->order("sort asc")->select();
            }
            $goods_html = $this->get_goods_list($m_goods ,$goods_param["style"] ,$node_num ,$cats);
            $goods_style_html = $goods_html["goods"];
            $goods_edit_html = $goods_html["edit"];
            $goods_style = $goods_param["style"];
        }else{
            $goods_style_html = $goods_edit_html = "";
            $goods_style = 1;
        }
        $html = "<div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='goods_{$node_num}'/>
                <ul class='goods_list' id='goods{$node_num}'>
                    {$goods_style_html}
                </ul>
                <span class='del_mod' onclick='del(this)'>移除</span>
                <div class='edit_form'>
                    <table cellpadding='1' cellspacing='0'>
                        <tr><td rowspan='2'>选择样式</td>
                            <td><img src='./Public/images/goods_style_1.jpg'/></td>
                            <td><img src='./Public/images/goods_style_2.jpg'/></td>
                        </tr>
                        <tr>
                            <td><input class='gs_{$node_num}' type='radio' name='goods_{$node_num}[style]' value='1' ".($goods_style == 1 ? "checked" : "")."/></td>
                            <td><input class='gs_{$node_num}' type='radio' name='goods_{$node_num}[style]' value='2' ".($goods_style == 2 ? "checked" : "")."/></td>
                        </tr>
                    </table>
                    <p style='color:red;'><i class='fa fa-exclamation-triangle'></i>商品与分类只能保存一种，分类权重更高。</p>
                    <p class='add_goods' data-sort='{$node_num}'><i class='fa fa-plus'></i>选商品</p>
                    <p class='choise_cates' data-sort='{$node_num}'><i class='fa fa-plus'></i>选类目（类目下的商品，默认销量降序）</p>
                    <div id='goods_added_{$node_num}' class='added_list'>{$goods_edit_html}</div>
                </div>
                <p class='clear'></p>
            </div>";
        return $html;
    }

    public function get_goods_list($conf , $style = 1 ,$node_num ,$cats = array())
    {
        $html = array();
        $class_name = $style == 1 ? "s1" : "s2";
        if(empty($cats)){
            foreach($conf as $v){
                $html["goods"] .= "<li class='{$class_name} goodsindex_{$v["id"]}'>
                        <img src='{$v["img"]}'/><p class='goods_name'>{$v["g_name"]}</p>
                        <p class='goods_amt'>￥{$v["price"]}</p></li>";
                $html["edit"] .= "<p style='overflow:hidden;text-overflow:ellipsis;white-space:nowrap;'><span>{$v["g_name"]}</span><i class='fa fa-close remove_goods'></i>
                        <input type='hidden' name='goods_{$node_num}[g_id][]' value='{$v["id"]}'/></p>";
            }
        }else{
            foreach($conf as $v){
                $html["goods"] .= "<li class='{$class_name} goodsindex_{$v["id"]}'>
                        <img src='{$v["img"]}'/><p class='goods_name'>{$v["g_name"]}</p>
                        <p class='goods_amt'>￥{$v["price"]}</p></li>";
            }
            foreach($cats as $c){
                $html["edit"] .= "<p><span>{$c["c_name"]}</span><i class='fa fa-close remove_goods'></i>
                        <input type='hidden' name='goods_{$node_num}[c_id][]' value='{$c["id"]}'/></p>";
            }
        }
        return $html;
    }

    public function blank( $height = 5 )
    {
        $node_num = self::get_rand_node();
        $html = <<<EOT
            <div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='blank_{$node_num}'/>
                <p class='empty_fill' style='height:{$height}px'></p>
                <span class='del_mod' onclick='del(this)'>移除</span>
                <div class='edit_form'>
                    <p>高度设置：<input type='number' class='w50' name='blank_{$node_num}[height]' onblur='changeBlankVal(this)' onkeyup='changeBlankVal(this)' value='{$height}'/></p>
                </div>
            </div>
EOT;
        return $html;
    }

    // 文字导航
    public function nav( $nav_param )
    {
        $node_num = self::get_rand_node();
        if(!empty($nav_param)){
            $title = $nav_param["title"];
        }else{
            $title = "请填写标题";
        }
        $html = "<div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='nav_{$node_num}'/>
                <p class='text_nav'>{$title}<span class='more_'>更多</span></p>
                <span class='del_mod' onclick='del(this)'>移除</span>
                <div class='edit_form'>
                    <p>标题：<input type='text' class='w150' name='nav_{$node_num}[title]' onblur='changeNavVal(this)' onkeyup='changeNavVal(this)' value='{$title}'/></p>
                    <p>设置链接：
                        <select class='w150 set_link' name='nav_{$node_num}[jump_link]' data-sort='{$node_num}'>
                            <option value='0'>请选链接</option>
                            <option value='1' ". ($nav_param["jump_link"] == 1 ? "selected" : "") .">会员主页</option>
                            <option value='2' ". ($nav_param["jump_link"] == 2 ? "selected" : "") .">店铺主页</option>
                            <option value='3' ". ($nav_param["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                            <option value='4' ". ($nav_param["jump_link"] == 4 ? "selected" : "") .">商品详情</option>
                            <option value='5' ". ($nav_param["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' ". ($nav_param["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                        <input type='text' class='w150' name='nav_{$node_num}[out_link]' placeholder='例：http://www.baidu.com/' value='{$nav_param["out_link"]}'/>
                    </p>
                    <p class='goods_p{$node_num}' ". ($nav_param["jump_link"] == 4 ? "" : "style='display:none;'") .">商品链接：
                        <input type='text' class='w150 goods_name_{$node_num}' readonly name='nav_{$node_num}[gname]' value='{$nav_param["gname"]}'/>
                        <input type='hidden' class='goods_id_{$node_num}' name='nav_{$node_num}[goods]' value='{$nav_param["goods"]}'/>
                    </p>
                    <p class='cates_p{$node_num}' ". ($nav_param["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                        <input type='text' class='w150 cates_name_{$node_num}' readonly name='nav_{$node_num}[cname]' value='{$nav_param["cname"]}'/>
                        <input type='hidden' class='cates_id_{$node_num}' name='nav_{$node_num}[cate]' value='{$nav_param["cate"]}'/>
                    </p>
                </div>
            </div>";
        return $html;
    }

    public function line( $line_param )
    {
        $node_num = self::get_rand_node();
        if(!empty($line_param)){
            $color = "";
            $width = "";
            $style = "";
        }else{
            $color = "#666";
            $width = "95%";
            $style = "solid";
        }
        $html = "<div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='line_{$node_num}'/>
                <p class='line_fill' style='width:{$width};border-bottom:1px {$style} {$color};'></p>
                <span class='del_mod' onclick='del(this)'>移除</span>
                <div class='edit_form'>
                    <p>颜色：<input type='text' id='picker' class='w100' name='line_{$node_num}[color]' onblur='changeBlankVal(this)' onkeyup='changeBlankVal(this)' value='{$color}'/></p>
                    <p>宽度：<input type='text' class='w100' name='line_{$node_num}[width]' onblur='changeLineWidthStyle(this)' onkeyup='changeLineWidthStyle(this)' value='{$width}'/></p>
                    <p>样式：
                        <input type='radio' ".($style == "solid" ? "checked" : "")." name='line_{$node_num}[style]' onchange='changeLineBorderStyle(this)' value='solid'/> 实线
                        <input type='radio' ".($style == "dashed" ? "checked" : "")." name='line_{$node_num}[style]' onchange='changeLineBorderStyle(this)' value='dashed'/> 虚线
                        <input type='radio' ".($style == "dotted" ? "checked" : "")." name='line_{$node_num}[style]' onchange='changeLineBorderStyle(this)' value='dotted'/> 点线
                    </p>
                </div>
            </div>";
        return $html;
    }

    public function search( )
    {
        $node_num = self::get_rand_node();
        $html = "<div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='search_{$node_num}'/>
                <input type='hidden' name='search_{$node_num}' value='1'/>
                <img src='./Public/images/search.png' class='search_img'/>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>";
        return $html;
    }

    public function notice( $notice_param = array())
    {
        $node_num = self::get_rand_node();
        $notice_html = "";
        if(!empty($notice_param)){
            foreach($notice_param as $nt_k => $nt_v){
                $notice_html .= $this->notice_list( $node_num ,$nt_k ,$nt_v );
            }
        }else{
            $notice_html = $this->notice_list( $node_num );
        }
        $html = "<div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='notice_{$node_num}'/>
                <img src='./Public/images/notice.png' class='notice_img'/>
                <div class='edit_form'>
                    <p class='add_notice' data-sort='{$node_num}'><i class='fa fa-plus'></i>加一条</p>
                    {$notice_html}
                </div>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>";
        return $html;
    }

    public function notice_list($node_num ,$notice_num = 0, $conf = array())
    {
        if($node_num == ""){
            $node_num = self::get_rand_node();
        }
        $title = "";
        if(!empty($conf)) $title = $conf["title"];
        $html = "<div class='single_notice' data-index='{$notice_num}'>
                    <p>标题：<input type='text' class='w250' name='notice_{$node_num}[title][]' maxlength='20' value='{$title}'/></p>
                    <p>设置链接：
                        <select class='w250 set_link' name='notice_{$node_num}[jump_link][]' data-sort='{$node_num}{$notice_num}'>
                            <option value='0'>请选链接</option>
                            <option value='1' ". ($conf["jump_link"] == 1 ? "selected" : "") .">会员主页</option>
                            <option value='2' ". ($conf["jump_link"] == 2 ? "selected" : "") .">店铺主页</option>
                            <option value='5' ". ($conf["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' ". ($conf["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                        <input type='text' class='w250' name='notice_{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$conf["linkurl"]}'/>
                    </p>
                    <p class='close_this_img'><span>移除</span></p>
                </div>";
        return $html;
    }

    public function banner( $banner_param = array() )
    {
        $node_num = self::get_rand_node();
        if(!empty($banner_param)){
            $banner_img = $banner_param[0]['img'];
            $pic_edit_html = $this->get_img_html("banner_" ,$node_num ,'' ,$banner_param);
        }else{
            $banner_img = "./Public/images/banner.jpg";
            $pic_edit_html = $this->get_img_html("banner_" ,$node_num);
        }
        $html = <<<EOT
            <div class="mod_list" data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='banner_{$node_num}'/>
                <div class="left_img">
                    <img src="{$banner_img}" class="banner_{$node_num}0"/>
                </div>
                <div class='edit_form'>
                    <p class="add_more" data-sort="{$node_num}" data-key="banner"><i class="fa fa-plus"></i>再加一张</p>
                    {$pic_edit_html}
                </div>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>
EOT;
        return $html;
    }

    // 自定义板块
    public function diy( $diy_param = array() )
    {
        $node_num = self::get_rand_node();
        if(!empty($diy_param)){
            $module = $diy_param[0]["module"];
            $module_html = $this->get_module("diy_" ,$module ,$node_num ,$diy_param);
            $show_html = $this->get_img_show($module ,$node_num ,$diy_param);
            $input_html = "<li class='mr4'><img src='./Public/images/diy_img_1.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='1' data-sort='{$node_num}' ".($module == 1 ? "checked" : "")."/></li>
                        <li><img src='./Public/images/diy_img_2.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='2' data-sort='{$node_num}' ".($module == 2 ?"checked" : "")."/></li>
                        <li class='mr4'><img src='./Public/images/diy_img_3.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='3' data-sort='{$node_num}' ".($module == 3 ?"checked" : "")."/></li>
                        <li><img src='./Public/images/diy_img_4.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='4' data-sort='{$node_num}' ".($module == 4 ? "checked" : "")."/></li>";
        }else{
            $module_html = $this->get_module("diy_" ,1 ,$node_num);
            $show_html = $this->get_img_show(1 ,$node_num);
            $input_html = "<li class='mr4'><img src='./Public/images/diy_img_1.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='1' data-sort='{$node_num}' checked/></li>
                        <li><img src='./Public/images/diy_img_2.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='2' data-sort='{$node_num}'/></li>
                        <li class='mr4'><img src='./Public/images/diy_img_3.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='3' data-sort='{$node_num}'/></li>
                        <li><img src='./Public/images/diy_img_4.jpg'/><input type='radio' name='diy_{$node_num}[module]' value='4' data-sort='{$node_num}'/></li>";
        }
        $html = <<<EOT
            <div class="mod_list" data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='diy_{$node_num}'/>
                <table cellspacing="0" cellpadding="0" class="table_html">
                    {$show_html}
                </table>
                <div class='edit_form'>
                    <ul class="diy_ul">{$input_html}</ul>
                    <div class="clear"></div>
                    <div class="diy_module">{$module_html}</div>
                </div>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>
EOT;
        return $html;
    }
    public function ad($ad_param = array())
    {
        $node_num = self::get_rand_node();
        if(empty($ad_param)){
            $ad_param["img"] = "./Public/images/ad.jpg";
            $ad_param["jump_link"] = 0;
            $select_html = <<<EOT
            <div class="single_img">
                <div class="f_left img_div">
                    <img src="./Public/images/add1.png" width="70" onClick="GetUploadify(1,'ad_{$node_num}','gallery','call_back');" class="ad_{$node_num}"/>
                </div>
                <div class="f_right">
                    <input type='hidden' value='{$ad_param["img"]}' name='ad_{$node_num}[img]' id="ad_{$node_num}"/>
                    <p>设置链接：
                        <select class='w150 set_link' name='ad_{$node_num}[jump_link]' data-sort="{$node_num}">
                            <option value='0'>请选链接</option>
                            <option value='1'>会员主页</option>
                            <option value='2'>店铺主页</option>
                            <option value='3'>商品分类</option>
                            <option value='4'>商品详情</option>
                            <option value='5'>外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' style='display:none;'>外部链接：
                        <input type='text' class='w150' name='ad_{$node_num}[out_link]' placeholder='例：http://www.baidu.com/'/>
                    </p>
                    <p class='goods_p{$node_num}' style='display:none;'>商品链接：
                        <input type='text' class='w150 goods_name_{$node_num}' readonly name='ad_{$node_num}[gname]'/>
                        <input type='hidden' class='goods_id_{$node_num}' name='ad_{$node_num}[goods]' value=''/>
                    </p>
                    <p class='cates_p{$node_num}' style='display:none;'>分类链接：
                        <input type='text' class='w150 cates_name_{$node_num}' readonly name='ad_{$node_num}[cname]'/>
                        <input type='hidden' class='cates_id_{$node_num}' name='ad_{$node_num}[cate]' value=''/>
                    </p>
                </div>
            </div>
EOT;
        }else{
            $select_html = "<div class='single_img'>
                <div class='f_left img_div'>
                    <img src='{$ad_param["img"]}' width='80' onClick=\"GetUploadify(1,'ad_{$node_num}','gallery','call_back');\" class='ad_{$node_num}'/>
                </div>
                <div class='f_right'>
                    <input type='hidden' value='{$ad_param["img"]}' name='ad_{$node_num}[img]' id='ad_{$node_num}'/>
                    <p>设置链接：
                        <select class='w150 set_link' name='ad_{$node_num}[jump_link]' data-sort='{$node_num}'>
                            <option value='0'>请选链接</option>
                            <option value='1' ". ($ad_param["jump_link"] == 1 ? "selected" : "") .">会员主页</option>
                            <option value='2' ". ($ad_param["jump_link"] == 2 ? "selected" : "") .">店铺主页</option>
                            <option value='3' ". ($ad_param["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                            <option value='4' ". ($ad_param["jump_link"] == 4 ? "selected" : "") .">商品详情</option>
                            <option value='5' ". ($ad_param["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' ". ($ad_param["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                        <input type='text' class='w150' name='ad_{$node_num}[out_link]' placeholder='例：http://www.baidu.com/' value='{$ad_param["out_link"]}'/>
                    </p>
                    <p class='goods_p{$node_num}' ". ($ad_param["jump_link"] == 4 ? "" : "style='display:none;'") .">商品链接：
                        <input type='text' class='w150 goods_name_{$node_num}' readonly value='{$ad_param["gname"]}' name='ad_{$node_num}[gname]'/>
                        <input type='hidden' class='goods_id_{$node_num}' name='ad_{$node_num}[goods]' value='{$ad_param["goods"]}'/>
                    </p>
                    <p class='cates_p{$node_num}' ". ($ad_param["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                        <input type='text' class='w150 cates_name_{$node_num}' readonly value='{$ad_param["cname"]}' name='ad_{$node_num}[cname]'/>
                        <input type='hidden' class='cates_id_{$node_num}' name='ad_{$node_num}[cate]' value='{$ad_param["cate"]}'/>
                    </p>
                    </div>
                    </div>";
        }
        $html = <<<EOT
            <div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='ad_{$node_num}'/>
                <img src='{$ad_param["img"]}' class='ad_list ad_{$node_num}'/>
                <span class='del_mod' onclick='del(this)'>移除</span>
                <div class='edit_form'>
                    {$select_html}
                </div>
            </div>
EOT;
        return $html;
    }
    // 解码html
    public function createHtml( $temps )
    {
        $html = "";
        if(!empty($temps)){
            foreach($temps as $temp){
                if($temp['temp_code'] == "blank"){
                    $conf = unserialize($temp['temp_conf']);
                    $html.= $this->blank($conf["height"]);
                }else{
                    $action = $temp['temp_code'];
                    $conf = unserialize($temp['temp_conf']);
                    $html.= $this->$action( $conf );
                }
            }
        }
        return $html;
    }

    public function get_img_html( $key ,$node_num = '', $img_nums = 0 ,$imgs_arr = array())
    {
        if($node_num == ""){
            $node_num = self::get_rand_node();
        }
        if(!empty($imgs_arr)){
            $html = "";
            foreach($imgs_arr as $k => $img){
                $html .= "<div class='single_img' data-index='{$k}'>
                <div class='f_left img_div'>
                    <img src='{$img["img"]}' width='70' onClick=\"GetUploadify(1,'{$key}{$node_num}{$k}','gallery','call_back');\" class='{$key}{$node_num}{$k}'/>
                </div>
                <div class='f_right'>
                    <input type='hidden' value='{$img["img"]}' name='{$key}{$node_num}[img][{$k}]' id='{$key}{$node_num}{$k}'/>
                    <p>设置链接：
                        <select class='w150 set_link' name='{$key}{$node_num}[jump_link][{$k}]' data-sort='{$node_num}{$k}'>
                            <option value='0'>请选链接</option>
                            <option value='1' ". ($img["jump_link"] == 1 ? "selected" : "") .">会员主页</option>
                            <option value='2' ". ($img["jump_link"] == 2 ? "selected" : "") .">店铺主页</option>
                            <option value='3' ". ($img["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                            <option value='4' ". ($img["jump_link"] == 4 ? "selected" : "") .">商品详情</option>
                            <option value='5' ". ($img["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' ". ($img["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                        <input type='text' class='w150' name='{$key}{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$img["linkurl"]}'/>
                    </p>
                    <p class='goods_p{$node_num}{$k}' ". ($img["jump_link"] == 4 ? "" : "style='display:none;'") .">商品链接：
                        <input type='text' class='w150 goods_name_{$node_num}{$k}' readonly name='{$key}{$node_num}[gname][{$k}]' value='{$img["gname"]}'/>
                        <input type='hidden' class='goods_id_{$node_num}{$k}' name='{$key}{$node_num}[goods][{$k}]' value='{$img["goods"]}'/>
                    </p>
                    <p class='cates_p{$node_num}{$k}' ". ($img["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                        <input type='text' class='w150 cates_name_{$node_num}{$k}' readonly name='{$key}{$node_num}[cname][{$k}]' value='{$img["cname"]}'/>
                        <input type='hidden' class='cates_id_{$node_num}{$k}' name='{$key}{$node_num}[cate][{$k}]' value='{$img["cate"]}'/>
                    </p>
                    <p class='close_this_img'><span>移除</span></p>
                </div>
            </div>";
            }
        }else{
            $html = <<<EOT
            <div class="single_img" data-index='{$img_nums}'>
                <div class="f_left img_div">
                    <img src="./Public/images/add1.png" width="70" onClick="GetUploadify(1,'{$key}{$node_num}{$img_nums}','gallery','call_back');" class="{$key}{$node_num}{$img_nums}"/>
                </div>
                <div class="f_right">
                    <input type='hidden' value='' name='{$key}{$node_num}[img][]' id="{$key}{$node_num}{$img_nums}"/>
                    <p>设置链接：
                        <select class='w150 set_link' name='{$key}{$node_num}[jump_link][]' data-sort="{$node_num}{$img_nums}">
                            <option value='0'>请选链接</option>
                            <option value='1'>会员主页</option>
                            <option value='2'>店铺主页</option>
                            <option value='3'>商品分类</option>
                            <option value='4'>商品详情</option>
                            <option value='5'>外部链接</option>
                        </select>
                    </p>
                    <p class='out_link' style='display:none;'>外部链接：
                        <input type='text' class='w150' name='{$key}{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/'/>
                    </p>
                    <p class='goods_p{$node_num}{$img_nums}' style='display:none;'>商品链接：
                        <input type='text' class='w150 goods_name_{$node_num}{$img_nums}' readonly name='{$key}{$node_num}[gname][]'/>
                        <input type='hidden' class='goods_id_{$node_num}{$img_nums}' name='{$key}{$node_num}[goods][]' value=''/>
                    </p>
                    <p class='cates_p{$node_num}{$img_nums}' style='display:none;'>分类链接：
                        <input type='text' class='w150 cates_name_{$node_num}{$img_nums}' readonly name='{$key}{$node_num}[cname][]'/>
                        <input type='hidden' class='cates_id_{$node_num}{$img_nums}' name='{$key}{$node_num}[cate][]' value=''/>
                    </p>
                    <p class='close_this_img'><span>移除</span></p>
                </div>
            </div>
EOT;
        }
        return $html;
    }

    public function get_module($key, $module = 1 ,$node_num = '' ,$imgs_arr = array())
    {
        if($node_num == ""){
            $node_num = self::get_rand_node();
        }
        if(!empty($imgs_arr)){
            $html = $this->get_img_html($key ,$node_num ,0 ,$imgs_arr);
        }else{
            if($module == 1)
            {
                $html = $this->get_img_html($key ,$node_num);
            }
            if($module == 2){
                $html = $this->get_img_html($key ,$node_num);
                $html .= $this->get_img_html($key ,$node_num ,1);
            }
            if($module == 3){
                $html = $this->get_img_html($key ,$node_num);
                $html .= $this->get_img_html($key ,$node_num ,1);
                $html .= $this->get_img_html($key ,$node_num ,2);
            }
            if($module == 4){
                $html = $this->get_img_html($key ,$node_num);
                $html .= $this->get_img_html($key ,$node_num ,1);
                $html .= $this->get_img_html($key ,$node_num ,2);
                $html .= $this->get_img_html($key ,$node_num ,3);
            }
        }
        return $html;
    }

    public function get_img_show( $module = 1 ,$node_num = '' ,$imgs_arr = array())
    {
        if(!empty($imgs_arr)){
            $img1 = $imgs_arr[0]["img"];
            $img2 = $imgs_arr[1]["img"];
            $img3 = $imgs_arr[2]["img"];
            $img4 = $imgs_arr[3]["img"];
        }else{
            $img1 = $img2 = $img3 = $img4 = "";
        }
        if($module == 1)
        {
            $html = "<tr><td><img src='{$img1}' id='diy_{$node_num}0img'/></td></tr>";
        }
        if($module == 2){
            $html = "<tr>
                        <td style='width:50%'><img src='{$img1}' id='diy_{$node_num}0img'/></td>
                        <td><img src='{$img2}' id='diy_{$node_num}1img'/></td>
                    </tr>";
        }
        if($module == 3){
            $html = "<tr>
                        <td rowspan='2' style='width:50%'><img src='{$img1}' id='diy_{$node_num}0img'/></td>
                        <td><img src='{$img2}' id='diy_{$node_num}1img'/></td>
                    </tr>";
            $html .= "<tr><td><img src='{$img3}' id='diy_{$node_num}2img'/></td></tr>";
        }
        if($module == 4){
            $html = "<tr>
                        <td rowspan='2' style='width:50%'><img src='{$img1}' id='diy_{$node_num}0img'/></td>
                        <td colspan='2'><img src='{$img2}' id='diy_{$node_num}1img'/></td>
                    </tr>";
            $html .= "<tr><td><img src='{$img3}' id='diy_{$node_num}2img'/></td>
                    <td><img src='{$img4}' id='diy_{$node_num}3img'/></td></tr>";
        }
        return $html;
    }

    // 优惠券
    public function coupon( $coupon_param = array())
    {
        $node_num = self::get_rand_node();
        if(!empty($coupon_param)){
            $module = $coupon_param[0]["module"];
            $coupon_img = array("./Public/images/coupon.jpg" ,"./Public/images/coupon.jpg");
        }else{
            $module = 1;
            $coupon_img = array("./Public/images/coupon.jpg" ,"./Public/images/coupon.jpg");
        }
        $html = "
            <div class='mod_list' data-sort='{$node_num}'>
                <input type='hidden' class='sort_node' value='coupon_{$node_num}'/>
                <table cellspacing='0' cellpadding='0' class='coupon_table'>
                    <tr>
                        <td style='width:50%'><img src='{$coupon_img[0]}' id='coupon_{$node_num}0img'/></td>
                        <td><img src='{$coupon_img[1]}' id='coupon_{$node_num}1img'/></td>
                    </tr>
                </table>
                <div class='edit_form'>
                    <ul class='coupon_ul'>
                        <li class='mr4'><img src='./Public/images/coupon_1.png'/>
                            <input type='radio' name='coupon_{$node_num}[module]' value='1' data-sort='{$node_num}' ".($module == 1 ? "checked" : "")."/>
                        </li>
                        <li><img src='./Public/images/coupon_1.png'/>
                            <input type='radio' name='coupon_{$node_num}[module]' value='2' data-sort='{$node_num}' ".($module == 2 ?"checked" : "")."/>
                        </li>
                    </ul>
                    <div class='clear'></div>
                    <div class='coupon_module'>

                    </div>
                </div>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>";
        return $html;
    }

    // 分类
    public function cats( $cats_param = array())
    {
        $node_num = self::get_rand_node();
        if(!empty($cats_param)){
            $cats_img = array($cats_param[0]["img"] ,$cats_param[1]["img"] ,$cats_param[2]["img"] ,$cats_param[3]["img"]);
            $up_img = array($cats_param[0]["img"] ,$cats_param[1]["img"] ,$cats_param[2]["img"] ,$cats_param[3]["img"]);
            $cat_names = array($cats_param[0]["cname"] ,$cats_param[1]["cname"] ,$cats_param[2]["cname"] ,$cats_param[3]["cname"]);
        }else{
            $cats_img = array("./Public/images/cats_1.png" ,"./Public/images/cats_2.png" ,"./Public/images/cats_3.png" ,"./Public/images/cats_4.png");
            $up_img = array("./Public/images/add1.png" ,"./Public/images/add1.png" ,"./Public/images/add1.png" ,"./Public/images/add1.png");
            $cat_names = array("类目1" ,"类目2" ,"类目3" ,"类目4");
        }
        $html = "
            <div class='mod_list' data-sort='{$node_num}' style='padding:5px 0;'>
                <input type='hidden' class='sort_node' value='cats_{$node_num}'/>
                <table cellspacing='0' cellpadding='0' class='cats_table'>
                    <tr>
                        <td><img src='{$cats_img[0]}' id='cats_{$node_num}0img'/><p id='cats_{$node_num}0title'>{$cat_names[0]}</p></td>
                        <td><img src='{$cats_img[1]}' id='cats_{$node_num}1img'/><p id='cats_{$node_num}1title'>{$cat_names[1]}</p></td>
                        <td><img src='{$cats_img[2]}' id='cats_{$node_num}2img'/><p id='cats_{$node_num}2title'>{$cat_names[2]}</p></td>
                        <td><img src='{$cats_img[3]}' id='cats_{$node_num}3img'/><p id='cats_{$node_num}3title'>{$cat_names[3]}</p></td>
                    </tr>
                </table>
                <div class='edit_form'>
                    <div class='single_img' data-index='0'>
                        <div class='f_left img_div'>
                            <img src='{$up_img[0]}' width='70' onClick=\"GetUploadify(1,'cats_{$node_num}0','gallery','call_back');\" class='cats_{$node_num}0'/>
                        </div>
                        <div class='f_right'>
                            <input type='hidden' value='{$cats_param[0]["img"]}' name='cats_{$node_num}[img][]' id='cats_{$node_num}0'/>
                            <p>设置链接：
                                <select class='w150 set_link' name='cats_{$node_num}[jump_link][]' data-sort='{$node_num}0'>
                                    <option value='0'>请选链接</option>
                                    <option value='3' ". ($cats_param[0]["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                                    <option value='5' ". ($cats_param[0]["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                                </select>
                            </p>
                            <p class='out_link' ". ($cats_param[0]["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                                <input type='text' class='w150' name='cats_{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$cats_param[0]["linkurl"]}'/>
                            </p>
                            <p class='cates_p{$node_num}0' ". ($cats_param[0]["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                                <input type='text' class='w150 cates_name_{$node_num}0' readonly name='cats_{$node_num}[cname][]' value='{$cats_param[0]["cname"]}'/>
                                <input type='hidden' class='cates_id_{$node_num}0' name='cats_{$node_num}[cate][]' value='{$cats_param[0]["cate"]}'/>
                            </p>
                        </div>
                    </div>
                    <div class='single_img' data-index='1'>
                        <div class='f_left img_div'>
                            <img src='{$up_img[1]}' width='70' onClick=\"GetUploadify(1,'cats_{$node_num}1','gallery','call_back');\" class='cats_{$node_num}1'/>
                        </div>
                        <div class='f_right'>
                            <input type='hidden' value='{$cats_param[1]["img"]}' name='cats_{$node_num}[img][]' id='cats_{$node_num}1'/>
                            <p>设置链接：
                                <select class='w150 set_link' name='cats_{$node_num}[jump_link][]' data-sort='{$node_num}1'>
                                    <option value='0'>请选链接</option>
                                    <option value='3' ". ($cats_param[1]["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                                    <option value='5' ". ($cats_param[1]["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                                </select>
                            </p>
                            <p class='out_link' ". ($cats_param[1]["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                                <input type='text' class='w150' name='cats_{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$cats_param[1]["linkurl"]}'/>
                            </p>
                            <p class='cates_p{$node_num}1' ". ($cats_param[1]["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                                <input type='text' class='w150 cates_name_{$node_num}1' readonly name='cats_{$node_num}[cname][]' value='{$cats_param[1]["cname"]}'/>
                                <input type='hidden' class='cates_id_{$node_num}1' name='cats_{$node_num}[cate][]' value='{$cats_param[1]["cate"]}'/>
                            </p>
                        </div>
                    </div>
                    <div class='single_img' data-index='2'>
                        <div class='f_left img_div'>
                            <img src='{$up_img[2]}' width='70' onClick=\"GetUploadify(1,'cats_{$node_num}2','gallery','call_back');\" class='cats_{$node_num}2'/>
                        </div>
                        <div class='f_right'>
                            <input type='hidden' value='{$cats_param[2]["img"]}' name='cats_{$node_num}[img][]' id='cats_{$node_num}2'/>
                            <p>设置链接：
                                <select class='w150 set_link' name='cats_{$node_num}[jump_link][]' data-sort='{$node_num}2'>
                                    <option value='0'>请选链接</option>
                                    <option value='3' ". ($cats_param[2]["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                                    <option value='5' ". ($cats_param[2]["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                                </select>
                            </p>
                            <p class='out_link' ". ($cats_param[2]["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                                <input type='text' class='w150' name='cats_{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$cats_param[2]["linkurl"]}'/>
                            </p>
                            <p class='cates_p{$node_num}2' ". ($cats_param[2]["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                                <input type='text' class='w150 cates_name_{$node_num}2' readonly name='cats_{$node_num}[cname][]' value='{$cats_param[2]["cname"]}'/>
                                <input type='hidden' class='cates_id_{$node_num}2' name='cats_{$node_num}[cate][]' value='{$cats_param[2]["cate"]}'/>
                            </p>
                        </div>
                    </div>
                    <div class='single_img' data-index='3'>
                        <div class='f_left img_div'>
                            <img src='{$up_img[3]}' width='70' onClick=\"GetUploadify(1,'cats_{$node_num}3','gallery','call_back');\" class='cats_{$node_num}3'/>
                        </div>
                        <div class='f_right'>
                            <input type='hidden' value='{$cats_param[3]["img"]}' name='cats_{$node_num}[img][]' id='cats_{$node_num}3'/>
                            <p>设置链接：
                                <select class='w150 set_link' name='cats_{$node_num}[jump_link][]' data-sort='{$node_num}3'>
                                    <option value='0'>请选链接</option>
                                    <option value='3' ". ($cats_param[3]["jump_link"] == 3 ? "selected" : "") .">商品分类</option>
                                    <option value='5' ". ($cats_param[3]["jump_link"] == 5 ? "selected" : "") .">外部链接</option>
                                </select>
                            </p>
                            <p class='out_link' ". ($cats_param[3]["jump_link"] == 5 ? "" : "style='display:none;'") .">外部链接：
                                <input type='text' class='w150' name='cats_{$node_num}[out_link][]' placeholder='例：http://www.baidu.com/' value='{$cats_param[3]["linkurl"]}'/>
                            </p>
                            <p class='cates_p{$node_num}3' ". ($cats_param[3]["jump_link"] == 3 ? "" : "style='display:none;'") .">分类链接：
                                <input type='text' class='w150 cates_name_{$node_num}3' readonly name='cats_{$node_num}[cname][]' value='{$cats_param[3]["cname"]}'/>
                                <input type='hidden' class='cates_id_{$node_num}3' name='cats_{$node_num}[cate][]' value='{$cats_param[3]["cate"]}'/>
                            </p>
                        </div>
                    </div>
                </div>
                <span class='del_mod' onclick='del(this)'>移除</span>
            </div>";
        return $html;
    }
}
